import os
import subprocess
import paramiko

project_path = r'E:\project\xb-chat-front'
os.chdir(project_path)

res = os.system('pnpm run build')
print(res, '打包前端项目完成')

zip_cmd = [r"D:\7-Zip\7z.exe", "a", "-tzip", 'dist.zip', 'dist']

res = subprocess.run(zip_cmd, shell=True)
print(res, '压缩前端项目完成')

scp_cmd = ['scp', 'dist.zip', 'mg:/project/xb_chat/']
res = subprocess.run(scp_cmd, shell=True)
print(res, '上传前端项目完成')


client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
private_key = paramiko.RSAKey.from_private_key_file(r"C:\Users\mg\.ssh\id_rsa")
username = 'root'
host = '47.110.92.205'
client.connect(host, username=username, pkey=private_key)
stdin, stdout, stderr = client.exec_command('cd /project/xb_chat/ && ./deploy_frontend.sh')
print(stdout.read().decode('utf-8'))
client.close()

# curl -X POST http://localhost:8000/order/crawl?passwd=FW249746 &
